(function ($) {
    //第一个demo，拖拽后显示操作图标，点击操作图标删除元素；
    $('#OA_task_1').on('tap', '.mui-btn', function (event) {
        var elem = this;
        var li = elem.parentNode.parentNode;
        mui.confirm('确认删除该条记录？', 'Hello MUI', btnArray, function (e) {
            if (e.index == 0) {
                li.parentNode.removeChild(li);
            } else {
                setTimeout(function () {
                    $.swipeoutClose(li);
                }, 0);
            }
        });
    });
    var btnArray = ['确认', '取消'];
})(mui);

//

var selectLength;//所有商品
var selectLength2 = 0; //已选商品
var ifGoods = GetQueryString('ifGoods');
if(ifGoods==1){
    $('#back').show();
}else{
    $('#back').hide();
}

function doAjax() {
    $.ajax({
        url: '/ShoppingCartC/getUserShoppingCart.json',
        dataType: 'json',
        data: {
            token: getItem('token'),
            // isSettlement:true,
            companyCode:getItem('companyCode'),
        },
        type: 'post',
        beforeSend:function () {
            $('<div class="loading"><img src="../phoneImg/jiazaizhong.gif"/></div>').appendTo($('#OA_task_2'));
        },
        success: function (data) {
            $('.loading').hide();
            if (data.code == 1) {
                $('#OA_task_2').empty();
                $('.mui-title').html('购物车(' + data.datas.length + ')');
                $('.total-num').html(data.rowCount + '件商品');
                var cartData = data.datas;
                if (cartData.length > 0) {
                    for (var i = 0; i < cartData.length; i++) {
                        var allSelectValue = '';
                        var hasSelect = '';
                        var ifCollections = '';
                        var goodsIfState = '';
                        if (cartData[i].isSelect) { // 表示当前商品选中
                            hasSelect = '../phoneImg/goods_pigeon.jpg';
                            allSelectValue = 'true';
                            selectLength2++;
                        } else {  //表示当前商品未选中
                            hasSelect = '../phoneImg/no_pigeon.jpg';
                            allSelectValue = 'false';
                        }
                        if(cartData[i].shoppingCartStateValue==5){
                            goodsIfState = '<div style="position: absolute;top: 0;left: 0;width: 100%;height: 100%;background: rgba(0,0,0,.1);z-index: 9999;"><img style="float: right;width: 95px;" src="../phoneImg/inValid_goods.png" alt=""></div>'
                        }else{
                            goodsIfState = ''
                        }
                        if(cartData[i].ifCollections){
                            ifCollections = '<a class="mui-btn mui-btn-grey del_collection" colId="'+cartData[i].collectionsId+'">取消<br>收藏</a>';
                        }else{
                            ifCollections = '<a class="mui-btn mui-btn-grey add_collection">加入<br>收藏</a>';
                        }
                        var goodsMainImg = cartData[i].mainImg.split(',')[0];
                        $('<li class="mui-table-view-cell mui-disabled" id="cartBox' + cartData[i].cartid + '">\n' +
                            '<div class="cart-goods-box mui-slider-handle"  cartId="' + cartData[i].cartid + '" goodsId="' + cartData[i].goodsId + '" specificationId="' + cartData[i].specificationId + '" goodsImg="' + goodsMainImg + '" price="' + cartData[i].memberPrice + '">' +
                            '<div class="mui-clearfix">\n' +
                            '<div class="cart-select-box"><img class="goodsSelect select" cartId="' + cartData[i].cartid + '" allselect="' + allSelectValue + '" src="' + hasSelect + '" price="' + cartData[i].memberPrice + '" count="' + cartData[i].count + '"/></div>\n' +
                            '<div class="cart-img-box"><img src="' + goodsMainImg + '"/></div>\n' +
                            '<div class="cart-product-box">\n' +
                            '<p class="cart-goods-name">' + cartData[i].goodsName + '</p>\n' +
                            '<p class="guige_box"><span class="guige" count="' + cartData[i].count + '" code="' + cartData[i].goodsCode + '" specificationId="' + cartData[i].specificationId + '">' + cartData[i].goodSpecificationName + '</span></p>\n' +
                            '<p class="price"><span class="cart-price">￥' + cartData[i].memberPrice + '</span><span class="choose_count"><span\n' +
                            'class="decreace"></span><input\n' +
                            'type="text" class="count" value="' + cartData[i].count + '"><span class="add"></span></span></p>\n' +
                            '</div></div>' +
                            '<div class="warranty_box mui-clearfix" id="warranty_box' + cartData[i].cartid + '"></div>' +
                            '</div>\n' +
                            '<div class="mui-slider-right mui-disabled">\n' +
                            ifCollections +
                            '<a class="mui-btn mui-btn-red delCart">删除</a></div>\n' +goodsIfState+
                            '</li>').appendTo($('#OA_task_2'));
                        var isService = cartData[i].valueAddedServicesList;
                        if (isService.length != 0) {
                            for (var j = 0; j < isService.length; j++) {
                                var isServiceValue = '';
                                if (isService[j].isSelect) {
                                    isServiceValue = '../phoneImg/goods_pigeon.jpg'
                                } else {
                                    isServiceValue = '../phoneImg/no_pigeon.jpg'
                                }
                                $('<div class="warranty_item mui-clearfix">\n' +
                                    '<img class="addSelect" src="' + isServiceValue + '" alt="" serviceId="' + isService[j].id + '">\n' +
                                    '<div class="warranty">' + isService[j].name + '</div>\n' +
                                    '<div class="warranty_price">￥' + isService[j].price + '</div>\n' +
                                    '<div class="warranty_buy" href="'+isService[j].detailsUrl+'">详情</div>\n' +
                                    '</div>').appendTo($('#warranty_box' + cartData[i].cartid + ''));
                            }
                        }

                    }
                    //收藏
                    mui('body').on('tap','.add_collection',function () {
                        var conThis = $(this);
                        var conId = conThis.parent().siblings().attr('goodsId');
                        $.ajax({
                            url: '/collectionsC/addCollections.json',
                            dataType: 'json',
                            data: {
                                goodsId: conId,
                                token: token,
                                companyCode:getItem('companyCode'),
                            },
                            type: 'post',
                            beforeSend:function(){
                                $('<div class="loading2"><span class="mui-spinner"></span></div>').appendTo($('body'));
                            },
                            success: function (data) {
                                $('.loading2').hide();
                                if (data.code == 1) {
                                    $('#collection_img').attr('src', '../phoneImg/collection_act.png');
                                    mui.toast('添加收藏成功');
                                    conThis.html('取消<br>收藏');
                                    conThis.attr('colId',data.datas.collectionsId);
                                    conThis.removeClass('add_collection').addClass('del_collection');
                                }
                                if (data.code == -1) {
                                    window.location.href = "login.html"
                                }
                                if (data.code == 0) {
                                    mui.toast(data.msg);
                                }
                            }
                        })
                    })
                    //取消收藏
                    mui('body').on('tap','.del_collection',function () {
                        var conThis = $(this);
                        var conId = conThis.attr('colId');
                        $.ajax({
                            url: '/collectionsC/delCollections.json',
                            dataType: 'json',
                            data: {
                                idStr: conId,
                                token: token,
                                companyCode:getItem('companyCode'),
                            },
                            type: 'post',
                            beforeSend:function(){
                                $('<div class="loading2"><span class="mui-spinner"></span></div>').appendTo($('body'));
                            },
                            success: function (data) {
                                $('.loading2').hide();
                                if (data.code == 1) {
                                    $('#collection_img').attr('src', '../phoneImg/collection.png')
                                    mui.toast('取消收藏成功');
                                    conThis.html('添加<br>收藏');
                                    conThis.addClass('add_collection').removeClass('del_collection');
                                }
                                if (data.code == -1) {
                                    window.location.href = "login.html"
                                }
                                if (data.code == 0) {
                                    mui.toast(data.msg);
                                }
                            }
                        })
                    })
                    //删除
                    mui('body').on('tap','.delCart',function () {
                        var delThis = $(this);
                        var delId = delThis.parent().siblings().attr('cartId');
                        $.ajax({
                            url: '/ShoppingCartC/deleteUserShoppingCart.json',
                            dataType: 'json',
                            data: {
                                id: delId,
                                token: token,
                                companyCode:getItem('companyCode'),
                            },
                            type: 'post',
                            beforeSend:function(){
                                $('<div class="loading2"><span class="mui-spinner"></span></div>').appendTo($('body'));
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    $('.loading2').hide();
                                    mui.toast('删除成功');
                                    window.location.reload();
                                }
                                if (data.code == -1) {
                                    window.location.href = "login.html"
                                }
                                if (data.code == 0) {
                                    mui.toast(data.msg);
                                }
                            }
                        })
                    })
                    mui('body').on('tap','.cart-goods-name',function () {
                        window.location.href="goods.html?goodsId="+$(this).parent().parent().parent().attr('goodsId');
                    })
                    mui('body').on('tap','.cart-img-box',function () {
                        window.location.href="goods.html?goodsId="+$(this).parent().parent().attr('goodsId');
                    })
                    mui('body').on('tap','.warranty_buy',function () {
                        window.location.href=$(this).attr('href');
                    })
                    selectLength = $('.goodsSelect').length;
                    if (selectLength2 == selectLength) { //是否全选
                        $('.allSelect').attr('src', '../phoneImg/goods_pigeon.jpg');
                    }
                    $('.total-price-price').html('¥ ' + data.totalMoney);
                    $('#jiesuan').html('结算(' + data.rowCount + ')');
                } else {
                    $('<div class="kong"><img src="../phoneImg/kong.png" alt="暂无数据"></div>').appendTo($('#OA_task_2'));
                    $('.cart-total-price,#edit').hide();
                }
            }
            if (data.code == -1) {
                $('.cart-kong').show();
                //$('.cart-total-price').hide();
            }
            if (data.code == 0) {
                mui.toast(data.msg);
            }
        }
    })
}

doAjax();



//编辑
$('#edit').click(function () {
    $('#edit').hide();
    $('#complete').show();
    $('.total-price').hide();
    $('#jiesuan').hide();
    $('#delete').show();
    $('.guige').each(function () {
        if ($(this).html() != '') {
            $(this).addClass('guige_h');
            $('<img src="../phoneImg/spe_edit.png"/>').appendTo($(this));
        }
    })

    //点击购物车里的单个规格
    $('.guige').click(function () {
        $('.detail_box').empty();
        var guigeThis = $(this);
        var goodsId = $(this).parent().parent().parent().parent().attr('goodsId');
        var goodsImg = $(this).parent().parent().parent().parent().attr('goodsImg');
        var goodsPrice = $(this).parent().parent().parent().parent().attr('price');
        var goodsCount = $(this).attr('count');
        $('.specification_img img').attr('src', goodsImg);
        $('#price').html('¥ ' + goodsPrice);
        $('.code').html('商品编号：' + $(this).attr('code'));
        var speWidth = $('.specification_img').width() / 100;
        var BodyWidth = $('body').width() * speWidth;
        $('.specification_img').css('height', '' + BodyWidth + 'px');
        $.ajax({
            url: '/specificationC/getSpecification.json',
            dataType: 'json',
            data: {
                goodid: goodsId,
                companyCode:getItem('companyCode'),
            },
            type: 'post',
            success: function (data) {
                var speData = data.datas;
                //规格
                for (var i = 0; i < speData.length; i++) {
                    $('<div class="detail_small_box" id="detail_spe' + speData[i].id + '"></div>').appendTo($('.detail_box'));
                    $('<div class="detail_title">' + speData[i].name + '</div>').appendTo($('#detail_spe' + speData[i].id + ''));
                    $('<div class="detail_spe mui-clearfix" id="detailOne_spe' + speData[i].id + '"></div>').appendTo($('#detail_spe' + speData[i].id + ''));
                    for (var b = 0; b < speData[i].data.length; b++) {
                        $('<div class="spe-one" parent="' + speData[i].id + '" son="' + speData[i].data[b].id + '" id="' + speData[i].data[b].id + '">' + speData[i].data[b].content + '</div>').appendTo($('#detailOne_spe' + speData[i].id + ''));
                    }
                }

            }
        })
        document.body.scrollTop = document.documentElement.scrollTop = 0;
        $('.specification_box').show();
        $('.specification_box').animate({
            opacity: 1,
            top: 0,
            height: '100%',
            visibility: 'visible'
        }, 200, function () {
            $('body,.mui-content').css({'height': '100%', 'overflow': 'hidden'});
        })

        //点击获取规格图片库存等信息
        $('body').on('click', '.spe-one', function () {
            $(this).addClass('spe_act');
            $(this).attr('ifAct', 'true');
            $(this).siblings().attr('ifAct', 'false');
            $(this).siblings().removeClass('spe_act');
            speB_Id = $(this).attr('parent');
            var o = $("div[ifAct='true']");
            param = '';
            for (var i = 0; i < o.length; i++) {
                param += $(o.get(i)).attr('parent') + ':' + $(o.get(i)).attr('son');
                if (i != o.length - 1) {
                    param += ','
                }
            }

            $.ajax({
                url: '/goodSpecificationC/getGoodSpecification.json',
                dataType: 'json',
                data: {
                    goodid: goodsId,
                    propertiesid: param,
                    companyCode:getItem('companyCode'),
                },
                type: 'post',
                success: function (data) {
                    //获取规格库存，图片
                    if (data.code == 1) {
                        $('#spe_img').attr('src', data.datas.image);
                        $('#price').html('¥' + data.datas.memberPrice);
                        propertiesId = data.datas.id;
                        propertiesName = data.datas.propertiesName;
                    }
                }
            })
        })

        //点击确定
        $('.spe_certain').click(function () {
            //获取已选择字符串拼接
            var speStr = '';
            $('.spe_act').each(function () {
                speStr += $(this).html() + ', ';
            })
            speStr += '* ' + $('.count').val();
            guigeThis.html(propertiesName + '<img src="../img/cart-choose.png">');
            guigeThis.attr('specificationId', propertiesId);
            $('.specification_box').hide();
            $('.specification_box').animate({
                opacity: 0,
                top: '100%',
                height: 0,
                visibility: 'hidden'
            }, 100, function () {
                $('body,.mui-content').css({'height': 'auto', 'overflow': 'auto'});
            })
        })
    })
})

//关闭
$('.colse_spe').click(function () {
    $('.specification_box').hide();
    $('.specification_box').animate({
        opacity: 0,
        top: '100%',
        height: 0,
        visibility: 'hidden'
    }, 100, function () {
        $('body,.mui-content').css({'height': 'auto', 'overflow': 'auto'});
    })
})

//完成
$('#complete').click(function () {
    var modifydata = '';
    $('.cart-goods-box').each(function () {
        var editCartId = 'id='+$(this).attr('cartId') + ':';
        var editCount = 'count='+$(this).children().find('.guige').attr('count') + ':';
        var speId = 'specificationId='+$(this).children().find('.guige').attr('specificationid') + ':';
        var serviceId = 'valueAddedServicesIds='+''+''
        modifydata += editCartId + editCount + speId + serviceId + ';';
    })
    $.ajax({
        url: '/ShoppingCartC/modifyUserShoppingCart.json',
        dataType: 'json',
        data: {
            token: getItem('token'),
            modifydata: modifydata,
            companyCode:getItem('companyCode'),
        },
        beforeSend:function(){
            $('<div class="loading2"><span class="mui-spinner"></span></div>').appendTo($('body'));
        },
        success: function (data) {
            if (data.code == 1) {
                $('.loading2').hide();
                doAjax();
                //$('#jiesuan').html('结算(' + data.datas.rowCount + ')');
                //$('.total-num').html(data.datas.rowCount + '件商品');
                $('#complete').hide();
                $('#edit').show();
                $('.total-price').show();
                $('#delete').hide();
                $('#jiesuan').show();
                var hasSelect2 = $(".goodsSelect[allSelect='true']").length;
                selectLength2 = hasSelect2;
            }
        }
    })
})

//选择增值服务
$('body').on('click', '.addSelect', function () {
    var selThis = $(this);
    var ifSelect = $(this).parent().parent().siblings().find('.goodsSelect').attr('src');
    var ifSelectValue = ''; //代表传入参数option
    var cartId = $(this).parent().parent().parent().attr('cartid');//代表传入参数cartID
    if (ifSelect == '../phoneImg/goods_pigeon.jpg') {
        ifSelectValue = true; //当前为选中，点击应变为未选中,所以传入参数为false
    } else {
        ifSelectValue = false; //当前未选中，点击应变为选中,所以传入参数为true
    }
    var isService = $(this).parent().siblings().find('.addSelect');
    var valueAddedServicesIds = '';
    if($(this).attr('src') == '../phoneImg/goods_pigeon.jpg'){
        valueAddedServicesIds = '';
    }else{
        valueAddedServicesIds = $(this).attr('serviceId')+','
    }
    $(isService).each(function () {
        if ($(this).attr('src') == '../phoneImg/goods_pigeon.jpg') {
            valueAddedServicesIds += $(this).attr('serviceId')+',';
        }
    })


    $.ajax({
        url: '/ShoppingCartC/optionCart.json',
        dataType: 'json',
        data: {
            token: getItem('token'),
            id: cartId,
            option: ifSelectValue,
            valueAddedServicesIds: valueAddedServicesIds,
            companyCode:getItem('companyCode'),
        },
        type: 'post',
        beforeSend:function(){
            $('<div class="loading2"><span class="mui-spinner"></span></div>').appendTo($('body'));
        },
        success: function (data) {
            $('.loading2').hide();
            if (data.code == 1) {
                var ifCount = selThis.parent().parent().siblings().find('.count').val();
                if(ifCount>1){
                    window.location.reload();
                }
                //计算价格
                if (selThis.attr('src') == '../phoneImg/no_pigeon.jpg') { //当前为未选中，变为已选
                    selThis.attr({'src': '../phoneImg/goods_pigeon.jpg', 'allSelect': 'true'});
                    $('.total-price-price').html('¥ '+data.datas.totalMoney);
                } else {  //当前为已选，变为未选
                    selThis.attr({'src': '../phoneImg/no_pigeon.jpg', 'allSelect': 'false'});
                    $('.total-price-price').html('¥ '+data.datas.totalMoney);
                }

            }
            if(data.code==0){
                mui.toast(data.msg);
            }
        }
    })
})


//选择商品
$('body').on('click', '.select', function () {
    var selThis = $(this);
    var ifSelect = $(this).attr('src');
    var ifSelectValue = ''; //代表传入参数option
    var cartId = selThis.attr('cartid');//代表传入参数cartID
    if (ifSelect == '../phoneImg/goods_pigeon.jpg') {
        ifSelectValue = false; //当前为选中，点击应变为未选中,所以传入参数为false
    } else {
        ifSelectValue = true; //当前未选中，点击应变为选中,所以传入参数为true
    }
    var isService = $(this).parent().parent().siblings().find('.addSelect');
    var valueAddedServicesIds = '';
    isService.each(function () {
        if ($(this).attr('src') == '../phoneImg/goods_pigeon.jpg') {
            valueAddedServicesIds += $(this).attr('serviceId')+',';
        }
    })

    $.ajax({
        url: '/ShoppingCartC/optionCart.json',
        dataType: 'json',
        data: {
            token: getItem('token'),
            id: cartId,
            option: ifSelectValue,
            valueAddedServicesIds: valueAddedServicesIds,
            companyCode:getItem('companyCode'),
        },
        type: 'post',
        beforeSend:function(){
            $('<div class="loading2"><span class="mui-spinner"></span></div>').appendTo($('body'));
        },
        success: function (data) {
            $('.loading2').hide();
            if (data.code == 1) {
                if (selThis.attr('src') == '../phoneImg/no_pigeon.jpg') { //当前为未选中，变为已选
                    selThis.attr({'src': '../phoneImg/goods_pigeon.jpg', 'allSelect': 'true'});
                    selectLength2++;

                } else {  //当前为已选，变为未选
                    selThis.attr({'src': '../phoneImg/no_pigeon.jpg', 'allSelect': 'false'});
                    selectLength2--;
                    $('.allSelect').attr('src', '../phoneImg/no_pigeon.jpg');
                }
                ifAll();
                //getTotalPrice();
                $('.total-price-price').html('¥ '+data.datas.totalMoney);
                var hasSelect = $(".goodsSelect[allSelect='true']").length;
                $('#jiesuan').html('结算(' + hasSelect + ')');
                $('.total-num').html(data.datas.rowCount + '件商品');
            }
            if(data.code==0){
                mui.toast(data.msg);
            }
        }
    })
})


function ifAll() {
    if (selectLength2 == selectLength) { //是否全选
        $('.allSelect').attr('src', '../phoneImg/goods_pigeon.jpg');
    }
}

//全选
$('.allSelect').click(function () {
    var option2;
    var selThis2 = $(this);
    if ($(this).attr('src') == '../phoneImg/no_pigeon.jpg') {
        option2 = 'true';
    } else {
        option2 = 'false';
    }
    $.ajax({
        url: '/ShoppingCartC/allSelect.json',
        dataType: 'json',
        data: {
            token: getItem('token'),
            isSelect: option2,
            companyCode:getItem('companyCode'),
        },
        type: 'post',
        beforeSend:function(){
            $('<div class="loading2"><span class="mui-spinner"></span></div>').appendTo($('body'));
        },
        success: function (data) {
            if (data.code == 1) {
                $('.loading2').hide();
                if (selThis2.attr('src') == '../phoneImg/no_pigeon.jpg') {
                    selThis2.attr('src', '../phoneImg/goods_pigeon.jpg');
                    $('.select').attr('src', '../phoneImg/goods_pigeon.jpg');
                    $('.goodsSelect').attr('allSelect', 'true');
                    selectLength2 = selectLength;
                } else {
                    selThis2.attr('src', '../phoneImg/no_pigeon.jpg');
                    $('.select').attr('src', '../phoneImg/no_pigeon.jpg');
                    $('.goodsSelect').attr('allSelect', 'false');
                    selectLength2 = 0;
                }
               // getTotalPrice();
                $('.total-price-price').html('¥ '+data.datas.totalMoney);
                $('#jiesuan').html('结算(' + selectLength2 + ')');
                $('.total-num').html(data.datas.rowCount + '件商品');
            }
        }
    })
})

//计算价格
function getTotalPrice() {
    var price = 0;
    $(".goodsSelect[allSelect='true']").each(function () {
        var unitPrice = $(this).attr('count') * $(this).attr('price');
        price += unitPrice;
    })

    $('.total-price-price').html('¥ ' + (price).toFixed(2));
}

getTotalPrice();

//删除
$('#delete').click(function () {
    var delId = '';
    $(".goodsSelect[allSelect='true']").each(function () {
        delId += $(this).attr('cartId') + ',';
    })
    $.ajax({
        url: '/ShoppingCartC/deleteUserShoppingCart.json',
        dataType: 'json',
        data: {
            token: getItem('token'),
            id: delId,
            companyCode:getItem('companyCode'),
        },
        type: 'post',
        beforeSend:function(){
            $('<div class="loading2"><span class="mui-spinner"></span></div>').appendTo($('body'));
        },
        success: function (data) {
            if (data.code == 1) {
                // $('.loading2').hide();
                // $('#complete').hide();
                // $('#edit').show();
                // $('.total-price').show();
                // $('#delete').hide();
                // $('#jiesuan').show();
                // var hasSelect3 = $(".goodsSelect[allSelect='true']").length;
                // $('#jiesuan').html('结算(' + hasSelect3 + ')');
                // $('.total-num').html(data.rowCount + '件商品');
                // doAjax();
                // $('.total-price-price').html('¥ 0.00');
                window.location.reload();
            }
        }
    })
})

$(document).ready(function () {
    //添加
    $("body").on('click', '.add', function () {
        var count = $(this).parent().find('input').val();
        count++;
        $(this).parent().find('input').val(count);
        $(this).parent().parent().siblings('.guige_box').find('.guige').attr('count',count);
        var cartId = $(this).parent().parent().parent().parent().parent().attr('cartId');
        var changeThis = $(this);
        changNum(changeThis,cartId,count);
    })
    //减少
    $("body").on('click', '.decreace', function () {
        var count2 = $(this).parent().find('input').val();
        count2--;
        if (count2 < 1) {
            count2 = 1;
        }
        $(this).parent().find('input').val(count2);
        $(this).parent().parent().siblings('.guige_box').find('.guige').attr('count',count2);
        var cartId = $(this).parent().parent().parent().parent().parent().attr('cartId');
        var changeThis = $(this);
        changNum(changeThis,cartId,count2);
    })
    //输入产品数量
    $("body").on('change', '.editCount', function () {
        //判断输入数量是否为空或小于1
        if ($(this).val() == "" || $(this).val() == NaN || $('this').val() < 1 || $('this').val() == null || $('this').val() == undefined) {
            $(this).val('1');
        }

    })
})

$(document).ready(function () {
    //添加
    $("body").on('click', '#add', function () {
        var count = $(this).parent().find('input').val();
        count++;
        $(this).parent().find('input').val(count);
    })
    //减少
    $("body").on('click', '#decreace', function () {
        var count2 = $(this).parent().find('input').val();
        count2--;
        if (count2 < 1) {
            count2 = 1;
        }
        $(this).parent().find('input').val(count2);
    })
    //输入产品数量
    $("body").on('change', '#count', function () {
        //判断输入数量是否为空或小于1
        if ($(this).val() == "" || $(this).val() == NaN || $('this').val() < 1 || $('this').val() == null || $('this').val() == undefined) {
            $(this).val('1');
        }
    })
})

//更改数量
function changNum(e,id,num) {
    $.ajax({
        url:'/ShoppingCartC/modifyCount.json',
        dataType:'json',
        data:{
            token:getItem('token'),
            id:id,
            count:num,
            companyCode:getItem('companyCode'),
        },
        type:'post',
        beforeSend:function(){
            $('<div class="loading2"><span class="mui-spinner"></span></div>').appendTo($('body'));
        },
        success:function (data) {
            $('.loading2').hide();
            if(data.code==1){
                var ifService = e.parent().parent().parent().parent().siblings().find('.addSelect');
                var ifHasService = false;
                if(num>1){
                    ifService.each(function () {
                        if($(this).attr('src')=='../phoneImg/goods_pigeon.jpg'){
                            ifHasService = true;
                            return;
                        }
                    })
                    if(ifHasService){
                        window.location.reload();
                    }else{
                        $('.loading2').hide();
                    }
                }
                $('.total-price-price').html('¥ ' + data.datas.totalMoney);
            }
            if(data.code==-1){
                window.location.href="login.html"
            }
            if(data.code==0){
                mui.toast(data.msg);
                return;
            }
        },
    })
}

//结算
$('#jiesuan').click(function () {
    if($(".goodsSelect[allSelect='true']").length==0){
        mui.toast('请选择商品');
        return;
    }
    removeItem('deliveryType');
    removeItem('payType');
    removeItem('addressId');
    window.location.href="confirmOrder.html?type=2"
})

mui('.mui-scroll-wrapper').scroll({
    deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
});

// if(document.getElementById('refreshContainer')==null||document.getElementById('refreshContainer')==undefined||document.getElementById('refreshContainer')==""){
// }else{
//     document.getElementById('refreshContainer').addEventListener("swiperight",function(){
//         history.back();
//     });
// }